package com.kzd.sdk.ui.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.kzd.sdk.base.OwnerActivity;
import com.kzd.sdk.callback.KZD_HttpCallback;
import com.kzd.sdk.callback.KZD_OnItemChildClickListener;
import com.kzd.sdk.core.KZD_ApiManager;
import com.kzd.sdk.entity.KZD_GameGift2;
import com.kzd.sdk.ui.adapter.KZD_GameGift2Adapter;
import com.kzd.sdk.utils.AppUtils;

import java.util.List;

public class KZD_UserGiftPackActivity extends OwnerActivity {

    public static void open(Context context) {
        Intent intent = new Intent(context, KZD_UserGiftPackActivity.class);
        context.startActivity(intent);
    }

    private RecyclerView rvUserGiftBody;

    private KZD_GameGift2Adapter mGameGiftAdapter;

    private final KZD_HttpCallback<List<KZD_GameGift2>> httpListenerGameGift = new KZD_HttpCallback<List<KZD_GameGift2>>() {
        @Override
        public void onSuccess(List<KZD_GameGift2> data) {
            mGameGiftAdapter.setNewInstance(data);
        }

        @Override
        public void onError(String error) {
            toast(error);
        }
    };

    @Override
    public String getLayoutIdByName() {
        return "kzd_activity_user_gift";
    }

    @Override
    public View getLayoutView() {
        return null;
    }

    @Override
    public void initView() {
        rvUserGiftBody = findViewById(AppUtils.getId(this, "rvUserGiftBody"));
        mGameGiftAdapter = new KZD_GameGift2Adapter(this);
        rvUserGiftBody.setLayoutManager(new LinearLayoutManager(this));
        rvUserGiftBody.setAdapter(mGameGiftAdapter);

        findViewById(AppUtils.getId((this),"ivBackPressed"))
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onBackPressed();
                    }
                });

        mGameGiftAdapter.setOnItemChildClickListener(new KZD_OnItemChildClickListener() {
            @Override
            public void onClick(View v, int position) {
                String no = mGameGiftAdapter.get(position)
                        .getCard_no();
                if (TextUtils.isEmpty(no)) {
                    return;
                }
                ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), no));
                toast("已复制");
            }
        });
    }

    @Override
    public void initData() {
        KZD_ApiManager.httpUserGift(httpListenerGameGift);
    }
}
